function affix(id, offsetHeight = 380, topHeight = 80, style = {}) {
    const dom = document.getElementById(id)
    if (dom) {
        window.addEventListener('scroll', e => {
            if (e.target.documentElement.scrollTop > offsetHeight) {
                for (const styleKey in style) {
                    dom.style[styleKey] = style[styleKey]
                }
                dom.style.position = 'fixed'
                dom.style.top = `${topHeight}px`
            } else {
                dom.style.position = 'relative'
                dom.style.top = ''

                for (const styleKey in style) {
                    dom.style[styleKey] = ''
                }
            }
        })
    }
}

// affix('affix')

layui.use('laypage', function(){
    var laypage = layui.laypage;
    laypage.render({
        elem: 'pages'
        ,count: pageCount
        ,limit: 10
        ,theme: '#03a9f4'
        ,curr: curr
        ,jump: function(obj, first){
            if(!first){
                //do something
                window.location.href = `${window.location.origin}/${window.location.pathname}?page=${obj.curr}`
            }
        }
    });
});

const list = new buildPage({
    template: `
        <div class="layui-panel user-info" style="height: 220px">
            <div class="user-left-image" :style="background: url('{{ userInfo.user_cover }}') no-repeat center center"></div>
            <div class="user-left-avatar" :style="background: url('{{ userInfo.avatar }}') no-repeat center center; background-size: 88px 86px;"></div>
            <div class="user-left-sigin" @click="jumpPage">{{ userInfo.nick_name }} [主页]</div>
        </div>
    `,
    data: {
        userInfo: {}
    },
    created () {
        this.StateX.getAction('getUserInfo', 'userInfo').then(data => {
            Reflect.set(this.data, 'userInfo', data)
        })
    },
    methods: {
        jumpPage() {
            if (this.data.userInfo.uid) to('/cms/home/cms-user-home')
            else to('/cms/home/cms-pages-sigin')
        }
    }
}).use({
    stateX
}).mount('#buildPageUserInfo')
